package cn.itcast.dome;

import cn.itcast.entity.Account;
import cn.itcast.mapper.AccountMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;
import java.util.List;

public class MybatisDemo {
    public static void main(String[] args) throws Exception{
        InputStream is = Resources.getResourceAsStream("sqlConfig.xml");
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(is);
        SqlSession session = factory.openSession();

        // todo 手动获取spring的代理对象
        AccountMapper mapper = session.getMapper(AccountMapper.class);

        List<Account> all = mapper.findAll();
        System.out.println("all :"+all.size());
        session.commit();
        session.close();
    }
}
